<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="房源ID" prop="propertyId">
        <el-input
          v-model="queryParams.propertyId"
          placeholder="请输入房源ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人" prop="auditorName">
        <el-input
          v-model="queryParams.auditorName"
          placeholder="请输入审核人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间" prop="auditTime">
        <el-date-picker clearable
          v-model="queryParams.auditTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:audit:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="auditList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="房源ID" align="center" prop="propertyId" />
      <el-table-column label="房源标题" align="center" prop="propertyTitle" />
      <el-table-column label="审核状态" align="center" prop="auditStatus">
        <template slot-scope="scope">
          <el-tag
            :type="getAuditStatusType(scope.row.auditStatus)"
            :effect="getAuditStatusEffect(scope.row.auditStatus)"
          >
            {{ getAuditStatusText(scope.row.auditStatus) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核备注" align="center" prop="auditRemark" />
      <el-table-column label="审核人姓名" align="center" prop="auditorName" />
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:audit:edit']"
            :disabled="scope.row.auditStatus !== 3"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handlePropertyView(scope.row)"
            v-hasPermi="['system:audit:edit']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改房源审核记录对话框 -->
    <el-dialog :title="title" :visible.sync="openOne" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="审核状态" prop="auditStatus">
          <el-select v-model="form.auditStatus" placeholder="审核状态" style="width: 100%">
            <el-option label="通过" :value="1" />
            <el-option label="拒绝" :value="2" />
            <el-option label="审核中" :value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="审核备注" prop="auditRemark">
          <el-input v-model="form.auditRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="propertyTitle" :visible.sync="openTwo" width="90%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <!-- 第一行：房源标题 -->
        <el-form-item label="房源标题" prop="propertyTitle">
          <el-input v-model="propertyForm.propertyTitle" placeholder="请输入房源标题" />
        </el-form-item>

        <!-- 图片上传区域 - 使用栅格布局 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="封面图片">
              <div class="upload-tip">封面（仅限1张）</div>
              <el-upload
                :action="uploadImgUrl"
                list-type="picture-card"
                :file-list="coverFileList"
                :headers="uploadHeaders"
                :on-preview="handlePreview"
                :on-remove="handleCoverRemove"
                :on-change="(file, fileList) => handleCoverChange(file, fileList)"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file, fileList) => handleCoverSuccess(response, file, fileList)"
                :on-error="handleUploadError"
                :limit="1"
                accept="image/*"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客厅图片">
              <div class="upload-tip">客厅（最多1张）</div>
              <el-upload
                :action="uploadImgUrl"
                list-type="picture-card"
                :file-list="livingRoomFileList"
                :headers="uploadHeaders"
                :on-preview="handlePreview"
                :on-remove="(file, fileList) => handleOtherRemove(file, fileList, 2)"
                :on-change="(file, fileList) => handleOtherChange(file, fileList, 2)"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file, fileList) => handleOtherSuccess(response, file, fileList, 2)"
                :on-error="handleUploadError"
                :limit="1"
                multiple
                accept="image/*"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="卧室图片">
              <div class="upload-tip">卧室（最多1张）</div>
              <el-upload
                :action="uploadImgUrl"
                list-type="picture-card"
                :file-list="bedroomFileList"
                :headers="uploadHeaders"
                :on-preview="handlePreview"
                :on-remove="(file, fileList) => handleOtherRemove(file, fileList, 3)"
                :on-change="(file, fileList) => handleOtherChange(file, fileList, 3)"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file, fileList) => handleOtherSuccess(response, file, fileList, 3)"
                :on-error="handleUploadError"
                :limit="1"
                multiple
                accept="image/*"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="厨房图片">
              <div class="upload-tip">厨房（最多1张）</div>
              <el-upload
                :action="uploadImgUrl"
                list-type="picture-card"
                :file-list="kitchenFileList"
                :headers="uploadHeaders"
                :on-preview="handlePreview"
                :on-remove="(file, fileList) => handleOtherRemove(file, fileList, 4)"
                :on-change="(file, fileList) => handleOtherChange(file, fileList, 4)"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file, fileList) => handleOtherSuccess(response, file, fileList, 4)"
                :on-error="handleUploadError"
                :limit="1"
                multiple
                accept="image/*"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="卫生间图片">
              <div class="upload-tip">卫生间（最多1张）</div>
              <el-upload
                :action="uploadImgUrl"
                list-type="picture-card"
                :file-list="bathroomFileList"
                :headers="uploadHeaders"
                :on-preview="handlePreview"
                :on-remove="(file, fileList) => handleOtherRemove(file, fileList, 5)"
                :on-change="(file, fileList) => handleOtherChange(file, fileList, 5)"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file, fileList) => handleOtherSuccess(response, file, fileList, 5)"
                :on-error="handleUploadError"
                :limit="1"
                multiple
                accept="image/*"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="阳台图片">
              <div class="upload-tip">阳台（最多1张）</div>
              <el-upload
                :action="uploadImgUrl"
                list-type="picture-card"
                :file-list="balconyFileList"
                :headers="uploadHeaders"
                :on-preview="handlePreview"
                :on-remove="(file, fileList) => handleOtherRemove(file, fileList, 6)"
                :on-change="(file, fileList) => handleOtherChange(file, fileList, 6)"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file, fileList) => handleOtherSuccess(response, file, fileList, 6)"
                :on-error="handleUploadError"
                :limit="1"
                multiple
                accept="image/*"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="环境图片">
              <div class="upload-tip">环境（最多1张）</div>
              <el-upload
                :action="uploadImgUrl"
                list-type="picture-card"
                :file-list="environmentFileList"
                :headers="uploadHeaders"
                :on-preview="handlePreview"
                :on-remove="(file, fileList) => handleOtherRemove(file, fileList, 7)"
                :on-change="(file, fileList) => handleOtherChange(file, fileList, 7)"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file, fileList) => handleOtherSuccess(response, file, fileList, 7)"
                :on-error="handleUploadError"
                :limit="1"
                multiple
                accept="image/*"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 房源描述 -->
        <el-form-item label="房源描述" prop="propertyDesc">
          <el-input
            v-model="propertyForm.propertyDesc"
            type="textarea"
            :rows="3"
            placeholder="请输入房源描述"
            maxlength="500"
            show-word-limit
          />
        </el-form-item>

        <!-- 地址信息 - 使用栅格布局 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="省份" prop="province">
              <el-input v-model="propertyForm.province" placeholder="请输入省份" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="城市" prop="city">
              <el-input v-model="propertyForm.city" placeholder="请输入城市" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="区县" prop="district">
              <el-input v-model="propertyForm.district" placeholder="请输入区县" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="街道" prop="street">
              <el-input v-model="propertyForm.street" placeholder="请输入街道" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="详细地址" prop="address">
          <el-input v-model="propertyForm.address" placeholder="请输入详细地址" />
        </el-form-item>

        <!-- 房屋基本信息 - 使用栅格布局 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="月租金" prop="monthlyRent">
              <el-input v-model="propertyForm.monthlyRent" placeholder="请输入月租金">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款周期" prop="paymentCycle">
              <el-select v-model="propertyForm.paymentCycle" placeholder="请选择付款周期" style="width: 100%">
                <el-option label="月付" :value="1" />
                <el-option label="季付" :value="2" />
                <el-option label="年付" :value="3" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="面积" prop="area">
              <el-input v-model="propertyForm.area" placeholder="请输入面积">
                <template slot="append">㎡</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="朝向" prop="orientation">
              <el-select v-model="propertyForm.orientation" placeholder="请选择朝向" style="width: 100%">
                <el-option label="东" value="东" />
                <el-option label="南" value="南" />
                <el-option label="西" value="西" />
                <el-option label="北" value="北" />
                <el-option label="东南" value="东南" />
                <el-option label="西南" value="西南" />
                <el-option label="东北" value="东北" />
                <el-option label="西北" value="西北" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="卧室数量" prop="bedroomCount">
              <el-input-number
                v-model="propertyForm.bedroomCount"
                :min="0"
                :max="10"
                placeholder="卧室数量"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客厅数量" prop="livingroomCount">
              <el-input-number
                v-model="propertyForm.livingroomCount"
                :min="0"
                :max="10"
                placeholder="客厅数量"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="所在楼层" prop="floor">
              <el-input v-model="propertyForm.floor" placeholder="请输入所在楼层" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="装修程度" prop="decoration">
              <el-select v-model="propertyForm.decoration" placeholder="请选择装修程度" style="width: 100%">
                <el-option label="毛坯" :value="1" />
                <el-option label="简装" :value="2" />
                <el-option label="精装" :value="3" />
                <el-option label="豪装" :value="4" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否有电梯" prop="hasElevator">
              <el-select v-model="propertyForm.hasElevator" placeholder="请选择是否有电梯" style="width: 100%">
                <el-option label="有电梯" :value="1" />
                <el-option label="无电梯" :value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="房东电话" prop="landlordPhone">
              <el-input v-model="propertyForm.landlordPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 备注 -->
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="propertyForm.remark"
            type="textarea"
            :rows="2"
            placeholder="请输入备注信息"
            maxlength="200"
            show-word-limit
          />
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listAudit, getAudit, delAudit, addAudit, updateAudit } from "@/api/system/audit"
import { listProperty, getProperty, delProperty, addProperty, updateProperty } from "@/api/system/property"
import {getToken} from "@/utils/auth";

export default {
  name: "Audit",
  props: {
    action: {
      type: String,
      default: "/common/upload"
    }
  },
  data() {
    return {
      uploadHeaders: {
        Authorization: 'Bearer ' + getToken()
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房源审核记录表格数据
      auditList: [],
      // 弹出层标题
      uploadImgUrl: process.env.VUE_APP_BASE_API + this.action,
      title: "",
      propertyTitle:"",
      // 是否显示弹出层
      openOne: false,
      openTwo: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        propertyId: null,
        auditStatus: null,
        auditRemark: null,
        auditorId: null,
        auditorName: null,
        auditTime: null
      },
      // 表单参数
      form: {},
      propertyForm: {},
      coverFileList: [],        // 封面图片列表 (类型1)
      livingRoomFileList: [],   // 客厅图片列表 (类型2)
      bedroomFileList: [],      // 卧室图片列表 (类型3)
      kitchenFileList: [],      // 厨房图片列表 (类型4)
      bathroomFileList: [],     // 卫生间图片列表 (类型5)
      balconyFileList: [],      // 阳台图片列表 (类型6)
      environmentFileList: [],  // 环境图片列表 (类型7)

      previewVisible: false,    // 预览对话框显示状态
      previewImageUrl: '',      // 预览图片URL
      // 图片类型映射
      imageTypeMap: {
        1: 'coverFileList',
        2: 'livingRoomFileList',
        3: 'bedroomFileList',
        4: 'kitchenFileList',
        5: 'bathroomFileList',
        6: 'balconyFileList',
        7: 'environmentFileList'
      },
      // 图片类型名称映射
      imageTypeNameMap: {
        1: '封面',
        2: '客厅',
        3: '卧室',
        4: '厨房',
        5: '卫生间',
        6: '阳台',
        7: '环境'
      },
      // 表单校验
      rules: {
        propertyId: [
          { required: true, message: "房源ID不能为空", trigger: "blur" }
        ],
        auditStatus: [
          { required: true, message: "审核状态(1:通过 2:拒绝)不能为空", trigger: "change" }
        ],
        auditorId: [
          { required: true, message: "审核人ID不能为空", trigger: "blur" }
        ],
        auditorName: [
          { required: true, message: "审核人姓名不能为空", trigger: "blur" }
        ],
        auditTime: [
          { required: true, message: "审核时间不能为空", trigger: "blur" }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取审核状态文本
    getAuditStatusText(status) {
      const statusMap = {
        1: '审核通过',
        2: '审核拒绝',
        3: '审核中'
      };
      return statusMap[status] || '未知状态';
    },

    // 获取审核状态标签类型
    getAuditStatusType(status) {
      const typeMap = {
        1: 'success',  // 通过 - 绿色
        2: 'danger',   // 拒绝 - 红色
        3: 'warning'   // 审核中 - 黄色
      };
      return typeMap[status] || 'info';
    },

    // 获取审核状态标签效果
    getAuditStatusEffect(status) {
      // 审核中使用亮色效果更醒目
      return status === 3 ? 'dark' : 'light';
    },
    handleCoverChange(file, fileList) {
      this.coverFileList = fileList;
    },
    // 其他类型图片变化
    handleOtherChange(file, fileList, imageType) {
      const fileListKey = this.imageTypeMap[imageType];
      if (fileList.length > 10) {
        const typeName = this.imageTypeNameMap[imageType];
        this.$message.warning(`${typeName}图片最多只能上传10张`);
        return;
      }
      this[fileListKey] = fileList;
    },
    // 封面图片删除
    handleCoverRemove(file, fileList) {
      this.coverFileList = fileList;
    },

    // 其他类型图片删除
    handleOtherRemove(file, fileList, imageType) {
      const fileListKey = this.imageTypeMap[imageType];
      this[fileListKey] = fileList;
    },

    // 封面图片上传成功
    handleCoverSuccess(response, file, fileList) {
      this.handleUploadSuccess(response, file, fileList, 1);
    },

    // 其他类型图片上传成功
    handleOtherSuccess(response, file, fileList, imageType) {
      this.handleUploadSuccess(response, file, fileList, imageType);
    },

    // 统一处理上传成功
    handleUploadSuccess(response, file, fileList, imageType) {
      if (response.code === 200) {
        const typeName = this.imageTypeNameMap[imageType];
        this.$message.success(`${typeName}图片上传成功`);
        // 更新文件信息
        file.url = response.url;
        file.name = response.fileName || file.name;
        // 更新对应的文件列表
        const fileListKey = this.imageTypeMap[imageType];
        this[fileListKey] = fileList.map(item => {
          if (item.uid === file.uid) {
            return {
              url: response.url,
              name: response.fileName || item.name,
              status: 'success'
            };
          }
          return item;
        });
      } else {
        this.$message.error(response.msg || '上传失败');
        // 上传失败时从文件列表中移除
        const fileListKey = this.imageTypeMap[imageType];
        this[fileListKey] = fileList.filter(item => item.uid !== file.uid);
      }
    },

    // 上传失败处理
    handleUploadError(error, file, fileList) {
      this.$message.error('图片上传失败，请重试');
      console.error('上传错误:', error);
    },

    // 或者使用更简单的方式 - 直接使用 el-image 的预览功能
    handlePreview(file) {
      console.log('Preview file:', file); // 调试信息

      // 获取图片URL - 多种方式尝试
      let imageUrl = '';

      if (file.url) {
        // 情况1: 直接有url
        imageUrl = file.url;
      } else if (file.response && file.response.url) {
        // 情况2: 从response中获取
        imageUrl = file.response.url;
      } else if (file.response && file.response.data) {
        // 情况3: 从response.data中获取
        imageUrl = file.response.data;
      } else if (file.raw) {
        // 情况4: 从raw文件中创建本地URL
        imageUrl = URL.createObjectURL(file.raw);
      }

      console.log('Image URL:', imageUrl); // 调试信息

      if (imageUrl) {
        this.previewImageUrl = imageUrl;
        this.previewVisible = true;
      } else {
        this.$message.warning('无法预览该图片');
      }
    },
    // 关闭预览
    handlePreviewClose() {
      this.previewVisible = false;
      this.previewImageUrl = '';
    },
    // 上传前校验
    beforeAvatarUpload(file) {
      const isImage = file.type === 'image/jpeg' ||
        file.type === 'image/png' ||
        file.type === 'image/jpg' ||
        file.type === 'image/gif' ||
        file.type === 'image/webp';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isImage) {
        this.$message.error('上传文件只能是 JPG、PNG、GIF 或 WebP 格式!');
        return false;
      }
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!');
        return false;
      }
      return true;
    },

    // 构建图片列表数据（用于提交表单）
    buildImageList() {
      const imageList = [];

      // 处理所有类型的图片
      [1, 2, 3, 4, 5, 6, 7].forEach(type => {
        const fileListKey = this.imageTypeMap[type];
        this[fileListKey].forEach(file => {
          // 如果文件已经上传成功，使用返回的URL
          const imageUrl = file.response ? file.response.url : file.url;

          if (imageUrl) {
            imageList.push({
              imageType: type,
              imageUrl: imageUrl,
              fileName: file.name
            });
          }
        });
      });

      return imageList;
    },

    // 设置图片文件列表（用于编辑时回显）
    setImageFileList(imageList) {
      // 清空所有文件列表
      Object.values(this.imageTypeMap).forEach(key => {
        this[key] = [];
      });

      // 根据图片类型分组设置
      imageList.forEach(image => {
        const fileListKey = this.imageTypeMap[image.imageType];
        if (fileListKey && this[fileListKey]) {
          this[fileListKey].push({
            uid: Date.now() + Math.random(),
            name: image.fileName || `image_${image.imageId}`,
            url: image.imageUrl,
            status: 'success',
            response: {
              url: image.imageUrl,
              fileName: image.fileName
            }
          });
        }
      });
    },
    // 重置所有图片列表
    resetImageLists() {
      Object.values(this.imageTypeMap).forEach(key => {
        this[key] = [];
      });
    },

    // 获取封面图片
    getCoverImage(property) {
      if (property.imageList && property.imageList.length > 0) {
        const coverImage = property.imageList.find(img => img.imageType === 1);
        return coverImage ? coverImage.imageUrl : property.imageList[0].imageUrl;
      }
      return '';
    },

    // 获取所有图片用于预览
    getAllImages(property) {
      if (property.imageList && property.imageList.length > 0) {
        return property.imageList.map(img => img.imageUrl).filter(url => url);
      }
      return [];
    },

    // 获取楼层信息
    getFloorText(property) {
      if (property.floor && property.totalFloors) {
        return `${property.floor}/${property.totalFloors}层`;
      } else if (property.floor) {
        return `${property.floor}层`;
      }
      return '楼层未知';
    },

    // 获取区域信息
    getAreaText(property) {
      return [property.city, property.district].filter(Boolean).join(' | ');
    },

    handlePropertyView(row) {
      this.reset()
      const propertyId = row.propertyId || this.ids
      getProperty(propertyId).then(response => {
        this.propertyForm = response.data
        this.openTwo = true
        this.propertyTitle = "查看房源信息"
        this.setImageFileList(response.data.imageList || [])
      })
    },
    /** 查询房源审核记录列表 */
    getList() {
      this.loading = true
      listAudit(this.queryParams).then(response => {
        this.auditList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.openOne = false
      this.openTwo = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        auditId: null,
        propertyId: null,
        auditStatus: null,
        auditRemark: null,
        auditorId: null,
        auditorName: null,
        auditTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.auditId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加房源审核记录"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const auditId = row.auditId || this.ids
      getAudit(auditId).then(response => {
        this.form = response.data
        this.openOne = true
        this.title = "修改房源审核记录"
      })
    },
    /** 提交按钮 */
    submitForm() {
      if (this.form.auditStatus === 3) {
        this.$message.error('不能选择审核中状态提交');
        return;
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.auditId != null) {
            updateAudit(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addAudit(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const auditIds = row.auditId || this.ids
      this.$modal.confirm('是否确认删除房源审核记录编号为"' + auditIds + '"的数据项？').then(function() {
        return delAudit(auditIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/audit/export', {
        ...this.queryParams
      }, `audit_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
